package com.xbongbong.crm.perform.query.render.insert;

import com.xbongbong.crm.abstracts.AbstractCrmNewPageRenderService;
import com.xbongbong.crm.help.WorkReportHelp;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataAddGetDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author sunshaoxiang
 * @ClassName WorkReportNewPageRenderServiceImpl
 * @Description 工作报告 add get 业务层
 * @Date 2022/6/8 14:04
 * @Version 1.0
 **/
@Service("workReportNewPageRenderServiceImpl")
public class WorkReportNewPageRenderServiceImpl extends AbstractCrmNewPageRenderService {

    public static final Logger LOGGER = LoggerFactory.getLogger(WorkReportNewPageRenderServiceImpl.class);

    @Resource
    private WorkReportHelp workReportHelp;

    @Override
    public List<Integer> businessType() {
        return Collections.singletonList(XbbRefTypeEnum.WORK_REPORT.getCode());
    }

    @Override
    public void businessHandleExplain(FormDataAddGetDTO formDataAddGetDTO, List<FieldAttrEntity> explainList, PaasFormEntityExt form) throws XbbException {
        FormatExplainDTO formatExplainDTO = new FormatExplainDTO();
        BeanUtil.copyProperties(formDataAddGetDTO, formatExplainDTO);
        formatExplainDTO.setExplainList(explainList);
        if (Objects.nonNull(formDataAddGetDTO.getSaasSpecialParamPojo())) {
            formatExplainDTO.setLinkBusinessType(formDataAddGetDTO.getSaasSpecialParamPojo().getLinkBusinessType());
        }
        workReportHelp.formatAddExplain(formatExplainDTO);

    }

    @Override
    public PaasFormEntityExt getForm(FormDataAddGetDTO formDataAddGetDTO) throws XbbException {
        PaasFormEntityExt paasFormEntityExt =  super.getForm(formDataAddGetDTO);
        formDataAddGetDTO.setSubBusinessType(paasFormEntityExt.getBusinessType());
        return paasFormEntityExt;
    }
}
